// packageA/pages/cleanWorkDetail/cleanWorkDetail.js
import CommonService from '../../../utils/service/commonService.js';
const util = require('../../../utils/util');
import Base64 from '../../../utils/Base64.js';
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //传参
    paramObj:null,     
    //信息回显
    editInfo:{}  
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { 
    if(options.paramObj){
      let paramObj=JSON.parse(options.paramObj);
      console.log('保洁工单详情传参');
      console.log(paramObj);

      this.setData({
        paramObj: paramObj
      })

      if(paramObj.id){
        //获取修改的数据
        this.getInfo();
      }
    }
  },

  confirmForm(e){
    console.log(e);
      console.log(this.data);
      const {editInfo,handleResultMessage} = this.data
      let param={
        className:'rabbitLog',
        data:{
          id:editInfo.id,
          state:1,
          handleResultMessage:handleResultMessage==null || handleResultMessage==""?"":handleResultMessage
        }
      }
      CommonService.goSave(param).then(res=>{
        if (res.statusCode == 200 && res.data.success == true){
          Toast.success('成功');
          setTimeout(() => {
            //返回列表页并刷新数据
            this.backAndRefresh();
          }, 1000);
        }else if(res.statusCode==202){
          Toast.fail('您操作太快了,请勿重复提交');
        }else{
          Toast.fail('操作失败');
        }
      }).catch((error) => {
        Toast.fail('操作失败');
      })
  },

    //返回列表页并刷新数据
    backAndRefresh(){
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
  
      prevPage.refreshListAndPage();
      wx.navigateBack();
    },

  //获取修改的数据
  getInfo(){
    let param = {
      isAuth: false,
      className: 'rabbitLog',
      data: {
        id:this.data.paramObj.id,
				selectFields: ['id','state','type','content','phoneNumber','userName','time','memberId','createDate','projectId','projectName','handleResultMessage'],
				nbl: Base64.encode(util.timeFormatDay(new Date()))
      }
    }

    CommonService.goFindList(param).then(res => {
      if(res.data.data && res.data.data.result && res.data.data.result.length) {
				let result=res.data.data.result[0];

        //状态
				switch(result.state){
					case 0:
						result.self_state='未读';
						result.self_stateClass='c-1';
						break;
					case 1:
						result.self_state='已读';
						result.self_stateClass='c-2';
						break;
				}
        console.log('异常人员提醒');
        console.log(result);
       
        this.setData({
          editInfo: result
        })
      }
    }).catch((error) => {
    })
  },
 //用户输入时清除错误提示
 clearMessage(e) {
  console.log("0000000000000099999999999999999999999999");
  console.log(e);
  let field = e.target.dataset.message;
  const value = e.detail;
  let obj = {};
  obj[field] = value;
  obj['disabled'] = false; 
  this.setData(obj);
 
  // let names = field
  //  // 更新 initTaskObj.name
  //  this.setData({
  //   [names]: value
  // });
},  
  //预览图片
  onPreviewImage(e) {
    let detail = e.target.dataset.detail;
    let src = e.target.dataset.src;
    console.log(e);
    wx.previewImage({
      current: src,
      urls: detail
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})